package com.mycc.game.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mycc.game.common.Code;
import com.mycc.game.common.Result;
import com.mycc.game.damin.Rules;
import com.mycc.game.damin.Scenario;
import com.mycc.game.service.ScenarioService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class ScenarioController {
    @Autowired
    private ScenarioService scenarioService;


    //查询所有场景信息
    @GetMapping("/selScenariosAll/{pageNumber}/{pageSize}")
    public Result selScenariosAll(@PathVariable Integer pageNumber, @PathVariable Integer pageSize) {
        IPage<Scenario> page = scenarioService.selAllScenarios(pageNumber, pageSize);
        if (page != null) {
            return new Result(Code.SELECT_OK, "ok", page);
        } else {
            return new Result(Code.SELECT_FAIL, "查询失败", null);
        }
    }

    //通过id查询场景信息
    @GetMapping("/selScenariosById/{id}/{pageNumber}/{pageSize}")
    public Result selScenariosById(@PathVariable Integer id, @PathVariable Integer pageNumber, @PathVariable Integer pageSize) {
        IPage<Scenario> page = scenarioService.selAllScenariosById(id, pageNumber, pageSize);
        if (page != null) {
            return new Result(Code.SELECT_OK, "ok", page);
        } else {
            return new Result(Code.SELECT_FAIL, "查询失败", null);
        }
    }

    //通过场景名称查询场景信息
    @GetMapping("/selScenariosByName/{name}/{pageNumber}/{pageSize}")
    public Result selScenariosByName(@PathVariable String name, @PathVariable Integer pageNumber, @PathVariable Integer pageSize) {
        IPage<Scenario> page = scenarioService.selAllScenariosByName(name, pageNumber, pageSize);
        if (page != null) {
            return new Result(Code.SELECT_OK, "ok", page);
        } else {
            return new Result(Code.SELECT_FAIL, "查询失败", null);
        }
    }

    //删除场景信息
    @GetMapping("/delScenariosById/{id}")
    public Result delScenariosById(@PathVariable Integer id) {
        boolean flag = scenarioService.delScenarioById(id);
        if (flag) {
            return new Result(Code.DELETE_OK, "删除成功", flag);
        } else {
            return new Result(Code.DELETE_FAIL, "删除失败", null);
        }
    }

    //新值场景信息
    @PostMapping("/addScenarios")
    public Result addScenarios(@RequestBody Scenario scenario) {
        boolean flag = scenarioService.addScenario(scenario);
        if (flag) {
            return new Result(Code.ADD_OK, "添加成功", flag);
        } else {
            return new Result(Code.ADD_FAIL, "添加失败", null);
        }
    }

    //修改场景信息
    @PutMapping("/updScenarios/{id}")
    public Result updScenarios(@PathVariable Integer id, @RequestBody Scenario scenario) {
        boolean flag = scenarioService.updScenario(id, scenario);
        if (flag) {
            return new Result(Code.ADD_OK, "修改成功", flag);
        } else {
            return new Result(Code.ADD_FAIL, "修改失败", null);
        }

    }
}
